package com.jia.leetCode;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-09 10:50
 */
public class Pro5483 {
    public String makeGood(String s) {

        int len = s.length();
        boolean[] flag = new boolean[len];
        while(true) {
            boolean isFind = false;
            int start = 0;
            for(; start < len; ) {
                if(!flag[start]) {
                    int next = start+1;
                    while(next < len && flag[next]) ++next;
                    if(next < len && !flag[next] && Math.abs(s.charAt(start) - s.charAt(next)) == 32) {
                        isFind = true;
                        flag[next] = true;
                        flag[start] = true;
                    }
                    start = next;
                }else {
                    start++;
                }
            }
            if(!isFind) break;
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < len; i++) {
            if(!flag[i]) {
                sb.append(s.charAt(i));
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Pro5483 pro5483  = new Pro5483();
        System.out.println(pro5483.makeGood("abBAcC"));
    }
}
